import { toArray } from '@v-c/utils'
import type { AccessEnum } from '~@/utils/constant'

export function useAccess() {
  const userStore = useUserStore()
  const type = computed(() => userStore.type)
  const hasAccess = (roles: (string | undefined)[] | string | undefined | AccessEnum) => {
    const accessRole = userStore.type
    const roleArr = toArray(roles).flat(1)
    return roleArr.includes(accessRole?.valueOf())
  }
  return {
    hasAccess,
    type,
  }
}
